package loan.calc.util;

import org.springframework.beans.BeanUtils;

import java.lang.reflect.Constructor;

public class POJOConverter {

    public static <T> T convert(Class<T> clazz, Object pojo) {
        try {
            Constructor<?> constructor = clazz.getConstructor();
            @SuppressWarnings("unchecked")
            T instance = (T) constructor.newInstance();
            BeanUtils.copyProperties(pojo, instance);
            return instance;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
